import java.util.*;

class Student {
    private  String id;

    public Student() {
    }
    public Student(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}



public class Test {
    public static void main6(String[] args) {
        HashBucket2<Student,String> hashBucket2 = new HashBucket2<>();
        hashBucket2.put(new Student("123"),"张三");
        hashBucket2.put(new Student("198"),"李四");
        hashBucket2.put(new Student("289"),"王五");
        hashBucket2.put(new Student("129"),"小明");
        hashBucket2.put(new Student("285"),"小红");
        hashBucket2.put(new Student("143"),"小黑");
        hashBucket2.put(new Student("159"),"小蓝");
        hashBucket2.put(new Student("219"),"小绿");
        System.out.println(hashBucket2.get(new Student("111")));
        System.out.println(hashBucket2.get(new Student("123")));
    }

    // hashCode()
    public static void main5(String[] args) {
        // 重写hashCode方法后，两个输出一样
        Student student1 = new Student("12");
        Student student2 = new Student("12");
        System.out.println(student1.hashCode());
        System.out.println(student2.hashCode());
    }

    // 哈希桶
    public static void main4(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(12,3);
        hashBucket.put(5,2);
        hashBucket.put(0,68);
        hashBucket.put(31,25);
        hashBucket.put(15,20);
        hashBucket.put(55,22);
        hashBucket.put(19,44);
        hashBucket.put(41,21);

        System.out.println(hashBucket.get(12));
        System.out.println(hashBucket.get(123));
        System.out.println(hashBucket.get(19));
    }

    // TreeSet
    public static void main3(String[] args) {
        Set<String> set1 = new TreeSet<>();
        set1.add("asd");
        set1.add("qwe");
        set1.add("zxc");
        // key不能重复
        // 因为TreeSet构造方法，利用了TreeMap
        System.out.println(set1);
    }

    // 测试TreeMap
    public static void main2(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        // key 一定要能比较
        // key不能重复，value可以

        // 设置key 和 val
        treeMap.put("y",12);
        treeMap.put("z",12);
        treeMap.put("x",43);

        System.out.println(treeMap);

        System.out.println("======");

        // 返回key对应的val
        System.out.println(treeMap.get("x"));
        System.out.println(treeMap.get("q"));

        // 返回key对应的val，若key不存在，返回默认值
        System.out.println(treeMap.getOrDefault("q",111));

        System.out.println("======");

        // 返回所有key的不重复集合
        Set<String> keySet = treeMap.keySet();
        System.out.println(keySet);

        // 返回所有value的可重复集合
        Collection<Integer> val = treeMap.values();
        System.out.println(val);

        System.out.println("======");

        // 解释 Map.Entry<>
        // Entry 是一个接口 在 Map接口内部
        // 返回所有的 key-value 映射关系
        Set<Map.Entry<String,Integer>> set = treeMap.entrySet();
        System.out.println(set);

        System.out.println("======");

        // 遍历集合set
        for (Map.Entry<String,Integer> entry:set) {
            System.out.println("key:"+entry.getKey()+" value:"+entry.getValue());
        }

    }

    // 测试搜索树
    public static void main1(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        binarySearchTree.insert(12);
        binarySearchTree.insert(22);
        binarySearchTree.insert(32);
        binarySearchTree.insert(2);
        binarySearchTree.insert(5);
        binarySearchTree.insert(10);
        binarySearchTree.insert(37);
        binarySearchTree.insert(27);
        binarySearchTree.insert(53);
        binarySearchTree.inorder(binarySearchTree.root);

        System.out.println();
        System.out.println(binarySearchTree.find(22).val);

        binarySearchTree.remove(10);
        binarySearchTree.inorder(binarySearchTree.root);

    }
}
